package chapter1.JavaObject.src.com.kkb.tz.bean;

import java.util.Objects;



//访问权限修饰符   类关键字   类名
public class Person {


	//访问权限修饰符  类型  成员变量名
	private String name;
	private int age;


	//          构造器  特殊的方法
	public Person() {
	}



	public Person(String name, int age) {
		this.name = name;
		this.age = age;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}


	//访问权限修饰符  返回类型  方法名  参数列表( 参数类型 参数名称 )
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public boolean equals(Object otherObject) {

		if (this == otherObject) {
			return true;
		}

		if (otherObject == null) {
			return false;
		}

		if (this.getClass() != otherObject.getClass()) {
			return false;
		}
		if (!(otherObject instanceof Person)) {
			return false;
		}

		Person other = (Person) otherObject;


		return Objects.equals(this.name, other.name) && this.age == other.age;
	}

	public static void main(String[] args) {
		Person p1 = new Person("Tom", 21);
		Person p2 = new Person("Marry", 20);
		System.out.println(p1 == p2);// false
		System.out.println(p1.equals(p2));// false
		Person p3 = new Person("Tom", 21);
		System.out.println(p1.equals(p3));// true
	}
}
